﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Web.SessionState;
using System.ComponentModel;
using System.Data;
using System.Web.UI.HtmlControls;

namespace iResume
{
    public partial class updateAdmin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                tbxName.Focus();

                ArrayList updateAdmin = new ArrayList();
               string email = (string)(Session["username"]);
              
               if (email == null)
               {
                   Response.Redirect("loginpage.aspx");
               }
                updateAdmin = DBManager.retrievead(email);
                Admin adminUpdate = new Admin();
                adminUpdate = (Admin)updateAdmin[0];
                Image2.ImageUrl = "AdminImg.ashx?id=" + adminUpdate.Email;
                tbxName.Text = adminUpdate.Fullname;
              //  tbxEmail.Text = adminUpdate.Email;
                tbxDob.Text = Convert.ToString(adminUpdate.Dateofbirth.ToString());
                rbtnGender.Text = adminUpdate.Gender;
                tbxAddress.Text = adminUpdate.Address;
                tbxPostalCode.Text = adminUpdate.Postalcode;
                ddlnational1.Text = adminUpdate.Nationality;
                contxb.Text = adminUpdate.Contact;

            
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click1(object sender, EventArgs e)
        {
            string username = (string)(Session["username"]);
            string password = (string)(Session["password"]);

            string fullname = tbxName.Text;
            //string email = tbxEmail.Text;
            DateTime dateofb = Convert.ToDateTime(tbxDob.Text);
            //DateTime dateofb = DateTime.ParseExact(tbxDob.Text, "dd/MM/yyyy", null);
            string gender = "";
            if (rbtnGender.SelectedValue != string.Empty)
            {
                gender = rbtnGender.SelectedValue;
            }
            string address = tbxAddress.Text;
            string postalcode = tbxPostalCode.Text;
            string nationality = ddlnational1.Text;
            string contact = contxb.Text;

            if (FileUploadImage1.PostedFile.FileName != "")
            {

                string imageType = FileUploadImage1.PostedFile.ContentType;
                byte[] imageData = new byte[FileUploadImage1.PostedFile.InputStream.Length + 1];
                FileUploadImage1.PostedFile.InputStream.Read(imageData, 0, imageData.Length);

                Admin a = new Admin(fullname, username, dateofb, gender, address, postalcode, nationality, contact, imageData);
                DBManager.updateadministrator(a);

                tbxName.Text = "";
                //    tbxEmail.Text = "";
                tbxDob.Text = "";
                gender = "";
                tbxAddress.Text = "";
                tbxPostalCode.Text = "";
                ddlnational1.Text = "";


                Response.Redirect("LoginAdmin.aspx");
            }
            else
            {
                

                Admin a = new Admin(fullname, username, dateofb, gender, address, postalcode, nationality, contact, null);
                DBManager.updateadministrator1(a);

                tbxName.Text = "";
                //    tbxEmail.Text = "";
                tbxDob.Text = "";
                gender = "";
                tbxAddress.Text = "";
                tbxPostalCode.Text = "";
                ddlnational1.Text = "";


                Response.Redirect("LoginAdmin.aspx");
            }
        }
    }
}